package com.qs.controller;


import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.tree.Tree;
import com.qs.annotation.OperationLog;
import com.qs.pojo.dto.AddressDto;
import com.qs.pojo.entity.Address;
import com.qs.pojo.vo.PayInfoVo;
import com.qs.response.Response;
import com.qs.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 后台管理首页（管理员和商家）
 * </p>
 *
 * @author author
 * @since 2023-11-21
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/index")
@RequiredArgsConstructor
public class IndexController {

    private final IUserService userService;

    private final IStoreService storeService;

    private final IGoodsService goodsService;

    private final IPayInfoService payInfoService;

    /**
     * 获取注册用户数量
     * @return
     */
    @GetMapping("/register/num")
    public Response getRegisterUserNum(){
        log.info("获取注册用户数量请求....");
        Map<String,Object> map = userService.findRegisterUserNum();
        return Response.success(map);
    }

    /**
     * 获取商户认证数量
     * @return
     */
    @GetMapping("/business/num")
    public Response getBusinessNum(){
        log.info("获取注册用户数量请求....");
        Map<String,Object> map = userService.findBusinessNum();
        return Response.success(map);
    }

    /**
     * 获取店铺数量
     * @return
     */
    @GetMapping("/store/num")
    public Response getStoreNum(){
        log.info("获取店铺数量请求....");
        Map<String,Object> map = storeService.findStoreNum();
        return Response.success(map);
    }

    /**
     * 获取商品数量
     * @return
     */
    @GetMapping("/goods/num")
    public Response getGoodsNum(){
        log.info("获取商品数量请求....");
        Map<String,Object> map = goodsService.findGoodsNum();
        return Response.success(map);
    }

    /**
     * 查询最近7天收益数据(管理员)
     * @return
     */
    @GetMapping("/admin/weekday")
    public Response getWeekdayData(){
        log.info("查询最近7天收益数据(管理员)请求....");
        List<Float> list = payInfoService.findWeekdayData();
        return Response.success(list);
    }

    /**
     * 查询最近7天收益数据(商户)
     * @return
     */
    @GetMapping("/business/weekday/{userId}")
    public Response getBusinessWeekdayData(@PathVariable("userId") Integer userId){
        log.info("查询最近7天收益数据(商户)请求....");
        List<Float> list = storeService.findBusinessWeekdayData(userId);
        return Response.success(list);
    }

    /**
     * 查询本周总流水
     * @return
     */
    @GetMapping("/week/total")
    public Response getWeekTotalOrderData(){
        log.info("查询本周总流水数据请求....");
        float weekdayTotal = payInfoService.findWeekTotalOrderData();
        return Response.success(weekdayTotal);
    }

    /**
     * 查询今年总流水
     * @return
     */
    @GetMapping("/this/year")
    public Response getThisYearData(){
        log.info("查询今年总流水数据请求....");
        float yearData = payInfoService.findThisYearData();
        return Response.success(yearData);
    }

    /**
     * 订单统计接口
     * @return
     */
    @GetMapping("/order/total")
    public Response getTotalOrderData(){
        log.info("订单统计数据请求....");
        Map<String,Object> map = payInfoService.findTotalOrderData();
        return Response.success(map);
    }

    /**
     * 商户商品订单统计
     * @return
     */
    @GetMapping("/goods/total/{userId}")
    public Response getGoodsTotal(@PathVariable("userId") Integer userId){
        log.info("商户商品订单统计数据请求....");
        Map<String,Object> map = storeService.findGoodsTotal(userId);
        return Response.success(map);
    }

    /**
     * 获取流水统计
     * @return
     */
    @GetMapping("/price/total/{userId}")
    public Response getTotalPrice(@PathVariable("userId") Integer userId){
        log.info("商户获取流水统计数据请求....");
        Map<String,Object> map = storeService.findTotalPrice(userId);
        return Response.success(map);
    }

    /**
     * 获取销量统计
     * @return
     */
    @GetMapping("/PineLine/total/{userId}")
    public Response getTotalPine(@PathVariable("userId") Integer userId){
        log.info("商户获取销量统计数据请求....");
        Map<String,Object> map = storeService.findPineLineToal(userId);
        return Response.success(map);
    }
}
